/**
 * 
 */



	//详细信息的展开收起
$(".details_more_btn").click(function() {
	$(".details_more_btn").parent().hide();
	$(this).parent().next().show();
	//展开后，右边的详细内容
	$(".details_text_height .show_more_right").each(function() {
		var spanheight = $(this).height();
		if(spanheight > '30') {
			var html = '';
			html += "<span class='fl details_right_more_btn other_morebtn'><img src='" + GV_IMG + "/details_leftarrow.jpg' /></span>"
			$(this).after(html);
			$(this).next().show();
			$(this).height(30);
		}
	})
})

$(document).ready(function() {
	var morenum = $(".details_text_hide .details_more").length;
	if(morenum > 0) {
		$(".details_more_btn").show();
	}

})
$(".details_stop_btn").click(function() {
	$(".details_more_btn").parent().show();
	$(this).parent().parent().hide();
})

$("body").on("click", ".details_right_more_btn", function() {
	var spanheight = $(this).parent().find(".show_more_right").height();
	if(spanheight > "30") {
		$(this).parent().find(".show_more_right").height(30);
		$(this).children("img").attr("src", GV_IMG + "/details_leftarrow.jpg")
		$(this).parent().find(".other_more").css("display", "block");
	} else {
		$(this).parent().find(".other_more").css("display", "none");
		$(this).children("img").attr("src", GV_IMG + "/details_bottomarrow.jpg")
		$(this).parent().find(".show_more_right").height("auto");
	}
})

//底部轮播案例
var case_i = 0;
var lilength = $(".case_swiper li").length;
if(lilength<="5"){
	$(".related_case .more_right").css("display","none");
}
$(".related_case .more_right").click(function(){
	case_i++;
	translatei = -1125 * case_i;
	var isnone = lilength - 5*case_i;
	$(".related_case .more_left").show();
	$(".case_swiper").css("transform","translateX("+translatei+"px)");
	if(isnone <= "5"){
		$(".related_case .more_right").css("display","none");
	}
})
$("body").on("click",".related_case .more_left",function(){
	case_i--;
	translatei = -1125 * case_i;
	$(".related_case .more_left").show();
	$(".case_swiper").css("transform","translateX("+translatei+"px)");
	if(case_i == "0"){
		$(".related_case .more_left").css("display","none");
	}
	var isnone = lilength - 5*case_i;
	if(isnone > "5"){
		$(".related_case .more_right").css("display","block");
	}
})


/*收藏标签*/
var _favorite_window = $("#favorite_content");//收藏标签编辑窗体
$("#btn_collect").click(function(){
	var isnone = _favorite_window.css("display");
	if(isnone == "none"){
		_favorite_window.show();
		$("#tags_1_tag").attr({maxlength:"12"});
		$("body").keydown(function() {
            if (event.keyCode == "13") {
				var tagnum = $("#tags_1_tagsinput .tag").length;
				if(tagnum>=1){
					$("#tags_1_tag").hide();
				}
			}
          })
		} else {
			_favorite_window.hide();
		}
	})
	
/*收藏，保存操作*/
$('#favorite-submit').click(function() {
	var tagnum = $("#tags_1_tagsinput .tag").length;

	if(tagnum>=2){
		$("#tags_1_tag").hide();
	}
	
	var _tag = $('#tags_1').val();
	$.post(_url_favorite,$('#favorite-form').serialize(),function(){
		$("#btn_collect").html("<img class='fl' src='"+GV_IMG+"/favorite_logo_focus.jpg' style='margin-top: 1px;'/>已收藏");
	});
	_favorite_window.hide();

})


/* 发表想法：评论点击提交 */
$('#comment-submit').click(function() {
	var _content = $('#details_comment_toptextarea').val();
	$.ajax({
		url: _url_comment,
		type: 'post',
		data: {
			'content': _content,
			'proid': _proid
		},
		beforeSend: function() {
			if(_content == '') {
				alert('请输入评论内容！！');
				return false;
			}
		},
		success: function(ret) {
			if(ret.status == 0) {
				alert(ret.info);
				return false;
			}else{
				var html = '<li>'
								+'<div class="comment_touxiang fl" style="background: url('+_userInfo_avatar+') no-repeat center;background-size: 100% 100%;"></div>'
								+'<div class=" comment_text">'
									+'<p class="fl comment_content"><span class="name">'+_userInfo_name+'</span><span style="margin-right: 10px;">&nbsp;:</span><span class="max_width">'+_content+'</span></p>'
									+'<p class="fl reply_btn" pid="'+ret.comment_id+'" touid="'+ret.to_uid+'">回复</p>'
									+'<div class="clear"></div>'
									+'<p class="comment_time"><span class="date">'+ret.created_time+'</span></p>'
								+'</div>'
								+'<div class="clear"></div>'	
							+'</li>';
					$('#comment_ul').prepend(html);
					$('#details_comment_toptextarea').val('');
			}
		}
	})
})


/* 评分：1.初始化评分效果 */
if (_user_score !== "0") {
	$(".score_submit .xin:lt("+_user_score+")").css("background-image","url("+GV_IMG+"/score_xinbg_hover.png)")
	$(".score_submit .score_text b").html(_user_score);
	$('.details_score .score_text').addClass('on');
	$('#score_submit').addClass('on');
}
/* 评分：2.点击爱心，获取爱心数目 */
$('.score_submit .xin').each(function(i){
	$(this).click(function(){
		if (_user_score !== "0") return false;
		var num = i+1;
		$('.score_submit .xin').css("background-image","url("+GV_IMG+"/score_xinbg.png)");
		$(".score_submit .xin:lt("+num+")").css("background-image","url("+GV_IMG+"/score_xinbg_hover.png)")
		$(".score_submit .score_text b").html(num);
	})
})
/* 评分：3.评分提交按钮触发动作*/
$("#score_submit").click(function(){
	$(".score_submit .xin").css("cursor","default")
	var _score = $(".score_submit .score_text b").html();
	if (_user_score!=='0' || _score == 0){
		return false;
	} 
	$.ajax({
		url:_url_score,
		data:{'score':_score,"proid":_proid},
		success:function(ret){
			if (!ret.status){
				alert(ret.info);
				return false;
			}
			_user_score = _score;//进行点击关闭
			$('.details_score .score_text').addClass('on');
			$('#score_submit').addClass('on');
		}
	})
})

//点赞,根据图片路径判断是否可以点击
var likeclick = $("#btn_like").attr("src");
$("#btn_like").click(function() {
	if(likeclick !== GV_IMG + "/like_logo.jpg") {
		$(this).attr("src", GV_IMG + "/like_logo.jpg")
			//当前点赞数num
		var num = $(this).next("span").html();

		num++;
		$(this).next("span").html(num);
		likeclick = GV_IMG + "/like_logo.jpg";
		$(this).css("cursor", "default");
		$.post(_url_like, {
			proid: _proid
		}, function(ret) {
			if(!ret.status) {
				alert(ret.info);
			}
		});
	}
})

$(function() {
	//导入标签数据
	$('#tags_1').importTags(_user_label);
	//标签编辑框
	$('#tags_1').tagsInput({
		width: 'auto',
		autocomplete_url: '__JS__/jquery.autocompleter.min.js',
		autocomplete: {
			'source': _url_label
		},
	});

});


/* 评论：1.回复评论内容 */
$("body").on("click",".reply_btn",function(){
	var isnone = $(this).parent().parent().find(".reply_input").css("display");
	var to_user = $(this).parent().find(".name").text();
	var _pid = $(this).attr('pid');
	var _touid = $(this).attr('touid');
	var html='';
	html+="<div class='reply_input'>"+
			"<div class='fl' style='line-height:28px;'>"+
			"回复<span class='fr reply_input_maxwid name_mar'>"+to_user+":</span>"+
			"</div>"+
			"<textarea class='fl reply_input_text' id='reply_input_text_"+_pid+"' name='' rows='' cols='' name=''  onpropertychange='checkLength(this,100);' oninput='checkLength(this,100);'></textarea>"+
			"<a href='javascript:;' class='fr reply_send_btn' style='margin-right: 7px;' onclick='replaySend("+_pid+","+_touid+")'>发送</a>"+
		 "</div>";
	if(isnone == "block"){
		return false;
	} else {
		$(this).parent().after(html);
		$(this).parent().next().show();
	}
})

/* 评论：2.回复评论，发送提交操作*/
function replaySend(_pid,_touid){
	var _content = $("#reply_input_text_"+_pid).val();
	$.ajax({
		url:_url_comment,
		type:'post',
		data:{'content':_content,'proid':_proid,'parentid':_pid,'to_uid':_touid},
		beforeSend:function(){
			if (_content == ''){
				alert('请输入评论内容！！');
				return false;
			}
		},
		success:function(ret){
			if (ret.status == 0){
				alert(ret.info);
				return false;
			}
			location.reload();		
		}
	})

}

/*评论点击更多*/
var c_num = $("#comment_ul li").length;
if(c_num>=5){
	$("#c_more").css("display","block")
}
	
var page = 0;
$("#c_more").click(function(){
	page++;
	$.ajax({
		type:"post",
		url:_url_comment_more,
		data:{'limit':5,'page': page},
		success:function(ret){
			var html="";
			for(var i in ret.list){
				if(ret.list[i].child.length == "0"){
					var head = ret.list[i].avatar;
					if(head == null){
						head = GV.IMG+"/comment_touxiang.jpg";
					}
					html="<li>"+
						"<div class='comment_touxiang fl' style='background: url("+head+") no-repeat center;background-size: 100% 100%;'></div>"+
							"<div class='comment_text'>"+
								"<p class='fl comment_content'><span class='name'>"+ret.list[i].nickname+"</span><span class='max_width'>"+ret.list[i].content+"</span></p>"+
									"<a href='javascript:;' class='fl reply_btn' touid='"+ret.list[i].id+"' pid='"+ret.list[i].uid+"' >回复</a>"+
							"<div class='clear'></div>"+
							"<p class='comment_time'><span class='date'>"+ret.list[i].created_time+"</span></p>"+
						"</div>"+
					"</li>";
					$(".comment_ul li").last().after(html)	
				}else{
					for(var j in ret.list[i].child){
						var child_head = ret.list[i].child[j].to_avatar;
						if(child_head == null){
							child_head = GV.IMG+"/comment_touxiang.jpg";
						}
						html="<li>"+
							"<div class='comment_touxiang fl' style='background: url("+head+") no-repeat center;background-size: 100% 100%;'></div>"+
								"<div class='comment_text'>"+
									"<p class='fl comment_content'><span class='name'>"+ret.list[i].nickname+"</span><span style='margin-right: 10px;'>&nbsp;:</span><span class='max_width'>"+ret.list[i].content+"</span></p>"+
										"<a href='javascript:;' class='fl reply_btn' touid='"+ret.list[i].id+"' pid='"+ret.list[i].uid+"' >回复</a>"+
								"<div class='clear'></div>"+
								"<p class='comment_time'><span class='date'>"+ret.list[i].created_time+"</span></p>"+
							"</div>"+
							"<div class='reply'>"+
								"<div class='reply_touxiang fl' style='background: url("+child_head+") no-repeat center;background-size: 100% 100%;'></div>"+
								"<div class='fl reply_text'>"+
									"<p class='fl reply_content'><span class='name' style='margin-right: 10px;'>"+ret.list[i].nickname+"</span>回复<span class='name name_mar'>"+ret.list[i].child[j].to_nickname+"</span><span style='margin-right: 10px;'>&nbsp;:</span>"+
									"<span class='max_width'>"+ret.list[i].child[j].content+"</span></p>"+
									"<div class='clear'></div>"+
									"<p class='comment_time'><span class='date'>"+ret.list[i].child[j].created_time+"</span></p>"+
								"</div>"+
								"<div class='clear'></div>"+
							"</div>"+
						"</li>";
						$(".comment_ul li").last().after(html)	
				}
				}
			}
		}
	});
})



/* 暂时废除······· */
$("body").on("click",".reply_send_btn0",function(){
//	var _content = $(this).parent().find('#')$('#details_comment_toptextarea').val();
	console.log('ss');
		$.ajax({
		url:"{:U('index/doComment')}",
		type:'post',
		data:{'content':_content,'proid':_proid},
		beforeSend:function(){
			if (_content == ''){
				alert('请输入评论内容！！');
				return false;
			}
		},
		success:function(ret){
			
		}
	})
	var html='';
		var textareaval = $(this).prev().val();
		$(this).parent().hide();
		html+="<div class='reply'>"+
		"<div class='reply_touxiang fl' style='background: url("+GV_IMG+"/comment_touxiang.jpg) no-repeat center;'></div>"+
		"<div class='fl reply_text'>"+
		"<p class='fl reply_content'><span class='name'>可爱的我:</span>回复<span class='name name_mar'>另一个可爱的我:</span><span class='max_width'>"+textareaval+"</span></p>"+
		"<div class='clear'></div>"+
		"<p class='comment_time'><span class='date'>2016-11-23</span><span>10:23:02</span></p>"+
		"</div>"+
		"<div class='clear'></div>"+
		"</div>"
		$(this).parent().after(html);
		
	


})

//输入框字数限制
function checkLength(obj, maxlength) {
	if(obj.value.length > maxlength) {
		obj.value = obj.value.substring(0, maxlength);
	}
}

//图片预览：没有系列作品的情况
layer.photos({
	  photos: '#detial-photos-box',
	  anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
	}); 

//图片预览：有系列作品的情况
$('.show-group-img').click(function(){
	var _groupid = $(this).attr('groupid');
	var _imageid = $(this).attr('imgageid');
	$.getJSON(_url_groupimg,{groupid:_groupid,imageid:_imageid}, function(json){
		layer.photos({
			photos: json,
			anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
		});
	}); 
}) 
  


var details_html="";
details_html+="<a href='#'>1111</a>"
$("#layui-layer-shade2").append(details_html)
